#include <pthread.h>
#include <stdio.h>

void *threadSafe(void *args) {
     int *threadId = (int *)args;
     printf("Hello from thread: %d\n", *threadId);
}

int main() {

    int i, j;

    int NUM_THREADS = 10;
    pthread_t threads[NUM_THREADS];
    int thread_args[NUM_THREADS];

    printf("Not in thread!\n");
    
    // changjian 10 xiancheng
    for (i = 0; i < NUM_THREADS; i++) {
        thread_args[i] = i;
        pthread_create(&threads[i], NULL, threadSafe, (void *)&thread_args[i]);
    }
    
    // wait 10 XIANCHENG wancheng
    for (j = 0; j < NUM_THREADS; j++) {
        pthread_join(threads[j], NULL);
    }

    printf("After thread!\n");

    pthread_exit(NULL);

    return 0;
}